package com.atguigu.gmall.product.service.impl;

import com.atguigu.gmall.common.execption.GmallException;
import com.atguigu.gmall.model.product.SkuAttrValue;
import com.atguigu.gmall.product.mapper.SkuAttrValueMapper;
import com.atguigu.gmall.product.service.SkuAttrValueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/***
 * sku平台属性值表service层实现类
 */
@Service
public class SkuAttrValueServiceImpl implements SkuAttrValueService {
    @Autowired
    private SkuAttrValueMapper skuAttrValueMapper;

    /**
     * 保存数据
     *
     * @param skuId
     * @param skuAttrValueList
     */
    @Override
    public void save(Long skuId, List<SkuAttrValue> skuAttrValueList) {
        //遍历保存
        skuAttrValueList.stream().forEach(skuAttrValue -> {
            //补全数据
            skuAttrValue.setSkuId(skuId);
            //调用dao层方法
            int insert = skuAttrValueMapper.insert(skuAttrValue);
            if(insert <= 0){
                throw new GmallException("新增sku信息表数据失败",null);
            }
        });
    }
}
